package com.google.android.gms.common.data;

import android.database.CursorIndexOutOfBoundsException;
import android.database.CursorWindow;
import android.net.Uri;
import android.os.Bundle;
import android.os.Parcel;
import android.util.Log;
import com.google.android.gms.common.internal.safeparcel.SafeParcelable;
import com.google.android.gms.internal.hm;
import java.util.ArrayList;
import java.util.HashMap;

public final class DataHolder implements SafeParcelable {
    public static final f CREATOR = new f();
    private static final a EO = new a(new String[0], null) {
    };
    private final int CT;
    private final String[] EG;
    Bundle EH;
    private final CursorWindow[] EI;
    private final Bundle EJ;
    int[] EK;
    int EL;
    private Object EM;
    private boolean EN = true;
    boolean mClosed = false;
    private final int xM;

    public static class a {
        private final String[] EG;
        private final ArrayList<HashMap<String, Object>> EP;
        private final String EQ;
        private final HashMap<Object, Integer> ER;
        private boolean ES;
        private String ET;

        private a(String[] strArr, String str) {
            this.EG = (String[]) hm.f(strArr);
            this.EP = new ArrayList();
            this.EQ = str;
            this.ER = new HashMap();
            this.ES = false;
            this.ET = null;
        }
    }

    DataHolder(int versionCode, String[] columns, CursorWindow[] windows, int statusCode, Bundle metadata) {
        this.xM = versionCode;
        this.EG = columns;
        this.EI = windows;
        this.CT = statusCode;
        this.EJ = metadata;
    }

    private void e(String str, int i) {
        if (this.EH == null || !this.EH.containsKey(str)) {
            throw new IllegalArgumentException("No such column: " + str);
        } else if (isClosed()) {
            throw new IllegalArgumentException("Buffer is closed.");
        } else if (i < 0 || i >= this.EL) {
            throw new CursorIndexOutOfBoundsException(i, this.EL);
        }
    }

    public long a(String str, int i, int i2) {
        e(str, i);
        return this.EI[i2].getLong(i, this.EH.getInt(str));
    }

    public int ae(int i) {
        int i2 = 0;
        boolean z = i >= 0 && i < this.EL;
        hm.A(z);
        while (i2 < this.EK.length) {
            if (i < this.EK[i2]) {
                i2--;
                break;
            }
            i2++;
        }
        return i2 == this.EK.length ? i2 - 1 : i2;
    }

    public boolean av(String str) {
        return this.EH.containsKey(str);
    }

    public int b(String str, int i, int i2) {
        e(str, i);
        return this.EI[i2].getInt(i, this.EH.getInt(str));
    }

    public String c(String str, int i, int i2) {
        e(str, i);
        return this.EI[i2].getString(i, this.EH.getInt(str));
    }

    public void close() {
        synchronized (this) {
            if (!this.mClosed) {
                this.mClosed = true;
                for (CursorWindow close : this.EI) {
                    close.close();
                }
            }
        }
    }

    public boolean d(String str, int i, int i2) {
        e(str, i);
        return Long.valueOf(this.EI[i2].getLong(i, this.EH.getInt(str))).longValue() == 1;
    }

    public int describeContents() {
        return 0;
    }

    public float e(String str, int i, int i2) {
        e(str, i);
        return this.EI[i2].getFloat(i, this.EH.getInt(str));
    }

    public Bundle eU() {
        return this.EJ;
    }

    public void eW() {
        int i;
        int i2 = 0;
        this.EH = new Bundle();
        for (i = 0; i < this.EG.length; i++) {
            this.EH.putInt(this.EG[i], i);
        }
        this.EK = new int[this.EI.length];
        i = 0;
        while (i2 < this.EI.length) {
            this.EK[i2] = i;
            i += this.EI[i2].getNumRows() - (i - this.EI[i2].getStartPosition());
            i2++;
        }
        this.EL = i;
    }

    String[] eX() {
        return this.EG;
    }

    CursorWindow[] eY() {
        return this.EI;
    }

    public byte[] f(String str, int i, int i2) {
        e(str, i);
        return this.EI[i2].getBlob(i, this.EH.getInt(str));
    }

    protected void finalize() throws Throwable {
        try {
            if (this.EN && this.EI.length > 0 && !isClosed()) {
                Log.e("DataBuffer", "Internal data leak within a DataBuffer object detected!  Be sure to explicitly call close() on all DataBuffer extending objects when you are done with them. (" + (this.EM == null ? "internal object: " + toString() : this.EM.toString()) + ")");
                close();
            }
            super.finalize();
        } catch (Throwable th) {
            super.finalize();
        }
    }

    public Uri g(String str, int i, int i2) {
        String c = c(str, i, i2);
        return c == null ? null : Uri.parse(c);
    }

    public int getCount() {
        return this.EL;
    }

    public int getStatusCode() {
        return this.CT;
    }

    int getVersionCode() {
        return this.xM;
    }

    public boolean h(String str, int i, int i2) {
        e(str, i);
        return this.EI[i2].isNull(i, this.EH.getInt(str));
    }

    public boolean isClosed() {
        boolean z;
        synchronized (this) {
            z = this.mClosed;
        }
        return z;
    }

    public void writeToParcel(Parcel dest, int flags) {
        f.a(this, dest, flags);
    }
}
